import SwiftUI
import Kingfisher

struct StoreInfoView: View {
    
    var model: FoodStoreItemModel
    var showRightIcon: Bool
    
    private var showStoreLocal: Bool {
        !model.distance.isEmpty
    }
    
    var body: some View {
        HStack(spacing: 8.0) {
            // 店铺图片
            KFImage(URL(string: model.storeImgUrl))
                .placeholder({
                    WebImageLoadingView()
                })
                .onFailureImage(.iconPlaceholderFood)
                .resizable()
                .frame(width: 68.0, height: 68.0)
                .clipShape(RoundedRectangle(cornerRadius: 8.0))
            // 店铺信息
            VStack(alignment: .leading, spacing: 6) {
                // 名称
                HStack(spacing: 2.0) {
                    Text(model.title)
                        .font(.alibabaPuHuiTi(size: 18.0, weight: .semiBold))
                        .foregroundStyle(.fs020000)
                        .lineLimit(1)
                    Spacer(minLength: 4.0)
                    if showRightIcon {
                        Image(.iconRight)
                    }
                }
                // 入驻认证标签
                HStack(spacing: 4.0) {
                    if model.isEntry {
                        EntryLabelView()
                    }
                    ForEach(model.tags, id: \.self) { tag in
                        TagView(tag: tag)
                    }
                }
                // 评分 和 地点
                HStack(spacing: 0) {
                    FoodPointsView(points: model.points, num: model.pointsPeopleNum)
                    Spacer()
                    if showStoreLocal {
                        Text("商圈地点·\(model.distance)km")
                            .font(.alibabaPuHuiTi(size: 14.0, weight: .regular))
                            .foregroundStyle(.fs575958)
                    }
                    
                }
            }
        }
        
    }
}
